package com.nerve.android.cloudoffice;

import java.util.HashMap;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.nerve.android.cloudoffice.domain.User;

/**
 * @项目名称 :bus966800
 * @文件名称 :BusApplication.java
 * @所在包 :com.nerve.bus
 * @功能描述 :application
 *
 * @创建者 :集成显卡	1053214511@qq.com
 * @创建日期 :2013-3-13
 * @修改记录 :
 */
public class OfficeApplication extends Application{
	
	public static Context context = null;
	
	public static boolean ISLOGIN = false;
	public static String LOGIN_NAME = null;
	
	public static User USER;
	
	public static String JSESSIONID = "";
	public static long LAST_LOGIN_TIME;
	/**
	 * 一个负责保存需要传递的信息的map
	 */
	private HashMap<String, Object> appData;
	
	public void putData(String key, Object obj){
		appData.put(key, obj);
	}
	/**
	 * @方法名称 :getData
	 * @功能描述 :clean 为true 时，那么在获取对象后，会清空map中的引用
	 * @return :Object
	 */
	public Object getData(String key, boolean clean){
		Object obj = appData.get(key);
		if(clean)
			appData.remove(key);
		return obj;
	}
	public void clearData(String key){
		appData.remove(key);
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
		appData = new HashMap<String, Object>();
		
		context = this;
		
		System.out.println("********************BUSApplication 启动成功！******************");
		Log.i("CellNote", "CellNoteApp start!");
	}
	
	public static void login(User u){
		if(u == null){
			return ;
		}
		USER = u;
		ISLOGIN = true;
		LAST_LOGIN_TIME = System.currentTimeMillis();
	}
	
	public static int getLoginId(){
		if(USER == null)
			return -1;
		
		return USER.getId();
	}
	
	/**
	 * @method name: isSaleManLogin
	 * @description: 是否销售部成员
	 * @return type: boolean
	 *
	 * @return
	 */
	public static boolean isSaleManLogin(){
		if(USER == null)
			return false;
		
		String dn = USER.getDepartment().getName();
		return dn.contains("销售部");
	}
}
